﻿var baseAddress = 'http://localhost:49595/MobileService/api/UserService/';
var url = "";

app.factory('userFactory', function ($http) {
    
    return {
        getLogin: function () {
            url = baseAddress + "GetUsersList";
            //return $http.post(url);
            return $http.get(url);
        },
        getUser: function (user) {
            url = baseAddress + "GetUser/" + user.UserId;
            return $http.get(url);
        },
        addUser: function (user) {
            url = baseAddress + "AddUser";
            return $http.post(url, user);
        },
        deleteUser: function (user) {
            url = baseAddress + "DeleteUser/" + user.UserId;
            return $http.delete(url);
        },
        updateUser: function (user) {
            url = baseAddress + "ModifyUser/" + user.UserId;
            return $http.put(url, user);
        }
    };
});


app.controller("LoginController", function ($scope, userFactory) {

     $scope.submitForm = function ($http) {
        
        // Set the 'submitted' flag to true
        $scope.submitted = true;
        var userName = $scope.userName;
        var password = $scope.password;
        debugger;
         userFactory.getLogin().success(function (data) {
             debugger;
             alert("Success : "+data)
            //$scope.users = data;
         }).error(function (data) {
             debugger;
             alert("Error :"+ data);
            $scope.error = "An Error has occured while Loading users! " + data.ExceptionMessage;
        });

    };
});

